home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 June / PersonalComputerWorld-June2009-CoverdiscCD.iso / Software / Freeware / Adobe AIR 1.5.1 / AdobeAIRInstaller.exe / setup.swf / scripts / mx / controls / ToolTip.as < prev    next >
Encoding:
Text File  |  2009-02-12  |  6.1 KB  |  197 lines

  1. package mx.controls
  2. {
  3.    import flash.display.DisplayObject;
  4.    import flash.text.TextFieldAutoSize;
  5.    import flash.text.TextFormat;
  6.    import mx.core.EdgeMetrics;
  7.    import mx.core.IFlexDisplayObject;
  8.    import mx.core.IFlexModuleFactory;
  9.    import mx.core.IFontContextComponent;
  10.    import mx.core.IRectangularBorder;
  11.    import mx.core.IToolTip;
  12.    import mx.core.IUITextField;
  13.    import mx.core.UIComponent;
  14.    import mx.core.UITextField;
  15.    import mx.core.mx_internal;
  16.    import mx.styles.ISimpleStyleClient;
  17.    
  18.    use namespace mx_internal;
  19.    
  20.    public class ToolTip extends UIComponent implements IToolTip, IFontContextComponent
  21.    {
  22.       mx_internal static const VERSION:String = "3.0.0.0";
  23.       
  24.       public static var maxWidth:Number = 300;
  25.       
  26.       private var textChanged:Boolean;
  27.       
  28.       private var _text:String;
  29.       
  30.       protected var textField:IUITextField;
  31.       
  32.       mx_internal var border:IFlexDisplayObject;
  33.       
  34.       public function ToolTip()
  35.       {
  36.          super();
  37.          mouseEnabled = false;
  38.       }
  39.       
  40.       public function set fontContext(param1:IFlexModuleFactory) : void
  41.       {
  42.          this.moduleFactory = param1;
  43.       }
  44.       
  45.       override public function styleChanged(param1:String) : void
  46.       {
  47.          super.styleChanged(param1);
  48.          if(param1 == "borderStyle" || param1 == "styleName" || param1 == null)
  49.          {
  50.             invalidateDisplayList();
  51.          }
  52.       }
  53.       
  54.       override protected function commitProperties() : void
  55.       {
  56.          var _loc1_:int = 0;
  57.          var _loc2_:TextFormat = null;
  58.          super.commitProperties();
  59.          if(hasFontContextChanged() && textField != null)
  60.          {
  61.             _loc1_ = getChildIndex(DisplayObject(textField));
  62.             mx_internal::removeTextField();
  63.             mx_internal::createTextField(_loc1_);
  64.             invalidateSize();
  65.             textChanged = true;
  66.          }
  67.          if(textChanged)
  68.          {
  69.             _loc2_ = textField.getTextFormat();
  70.             _loc2_.leftMargin = 0;
  71.             _loc2_.rightMargin = 0;
  72.             textField.defaultTextFormat = _loc2_;
  73.             textField.text = _text;
  74.             textChanged = false;
  75.          }
  76.       }
  77.       
  78.       mx_internal function getTextField() : IUITextField
  79.       {
  80.          return textField;
  81.       }
  82.       
  83.       override protected function createChildren() : void
  84.       {
  85.          var _loc1_:Class = null;
  86.          super.createChildren();
  87.          if(!mx_internal::border)
  88.          {
  89.             _loc1_ = getStyle("borderSkin");
  90.             mx_internal::border = new _loc1_();
  91.             if(mx_internal::border is ISimpleStyleClient)
  92.             {
  93.                ISimpleStyleClient(mx_internal::border).styleName = this;
  94.             }
  95.             addChild(DisplayObject(mx_internal::border));
  96.          }
  97.          mx_internal::createTextField(-1);
  98.       }
  99.       
  100.       override protected function measure() : void
  101.       {
  102.          var _loc7_:Number = NaN;
  103.          super.measure();
  104.          var _loc1_:EdgeMetrics = borderMetrics;
  105.          var _loc2_:Number = _loc1_.left + getStyle("paddingLeft");
  106.          var _loc3_:Number = _loc1_.top + getStyle("paddingTop");
  107.          var _loc4_:Number = _loc1_.right + getStyle("paddingRight");
  108.          var _loc5_:Number = _loc1_.bottom + getStyle("paddingBottom");
  109.          var _loc6_:Number = _loc2_ + _loc4_;
  110.          _loc7_ = _loc3_ + _loc5_;
  111.          textField.wordWrap = false;
  112.          if(textField.textWidth + _loc6_ > ToolTip.maxWidth)
  113.          {
  114.             textField.width = ToolTip.maxWidth - _loc6_;
  115.             textField.wordWrap = true;
  116.          }
  117.          measuredWidth = textField.width + _loc6_;
  118.          measuredHeight = textField.height + _loc7_;
  119.       }
  120.       
  121.       public function get fontContext() : IFlexModuleFactory
  122.       {
  123.          return moduleFactory;
  124.       }
  125.       
  126.       public function set text(param1:String) : void
  127.       {
  128.          _text = param1;
  129.          textChanged = true;
  130.          invalidateProperties();
  131.          invalidateSize();
  132.          invalidateDisplayList();
  133.       }
  134.       
  135.       public function get text() : String
  136.       {
  137.          return _text;
  138.       }
  139.       
  140.       mx_internal function removeTextField() : void
  141.       {
  142.          if(textField)
  143.          {
  144.             removeChild(DisplayObject(textField));
  145.             textField = null;
  146.          }
  147.       }
  148.       
  149.       mx_internal function createTextField(param1:int) : void
  150.       {
  151.          if(!textField)
  152.          {
  153.             textField = IUITextField(createInFontContext(UITextField));
  154.             textField.autoSize = TextFieldAutoSize.LEFT;
  155.             textField.mouseEnabled = false;
  156.             textField.multiline = true;
  157.             textField.selectable = false;
  158.             textField.wordWrap = false;
  159.             textField.styleName = this;
  160.             if(param1 == -1)
  161.             {
  162.                addChild(DisplayObject(textField));
  163.             }
  164.             else
  165.             {
  166.                addChildAt(DisplayObject(textField),param1);
  167.             }
  168.          }
  169.       }
  170.       
  171.       override protected function updateDisplayList(param1:Number, param2:Number) : void
  172.       {
  173.          super.updateDisplayList(param1,param2);
  174.          var _loc3_:EdgeMetrics = borderMetrics;
  175.          var _loc4_:Number = _loc3_.left + getStyle("paddingLeft");
  176.          var _loc5_:Number = _loc3_.top + getStyle("paddingTop");
  177.          var _loc6_:Number = _loc3_.right + getStyle("paddingRight");
  178.          var _loc7_:Number = _loc3_.bottom + getStyle("paddingBottom");
  179.          var _loc8_:Number = _loc4_ + _loc6_;
  180.          var _loc9_:Number = _loc5_ + _loc7_;
  181.          mx_internal::border.setActualSize(param1,param2);
  182.          textField.move(_loc4_,_loc5_);
  183.          textField.setActualSize(param1 - _loc8_,param2 - _loc9_);
  184.       }
  185.       
  186.       private function get borderMetrics() : EdgeMetrics
  187.       {
  188.          if(mx_internal::border is IRectangularBorder)
  189.          {
  190.             return IRectangularBorder(mx_internal::border).borderMetrics;
  191.          }
  192.          return EdgeMetrics.EMPTY;
  193.       }
  194.    }
  195. }
  196.  
  197.